
class CheckSystem {
	
	CheckSystem() {
		
	}
	
	int[] CardCheck (PlayerInterface x) {
		int result[] = {0,0,0,0,0,0}; 
		
		if(x.hand[0].Value() == x.hand[1].Value()) {
			if(x.hand[0].Value() == x.hand[2].Value()) {
				if(x.hand[0].Value() == x.hand[3].Value()) {
					result[0] = 7;
					result[1] = x.hand[3].Value();
					result[2] = x.hand[4].Value();
				}
				else {
					if(x.hand[3].Value() == x.hand[4].Value()) {
						result[0] = 6;
						result[1] = x.hand[2].Value();
						result[2] = x.hand[4].Value();
					}
					else {
						result[0] = 3;
						result[1] = x.hand[2].Value();
					}
				}
			}
			else {
				if(x.hand[2].Value() == x.hand[3].Value()) {
					if(x.hand[2].Value() == x.hand[4].Value()) {
						result[0] = 6;
						result[1] = x.hand[4].Value();
						result[2] = x.hand[1].Value();
					}
					else {
						result[0] = 2;
						result[1] = x.hand[3].Value();
						result[2] = x.hand[1].Value();
						result[3] = x.hand[4].Value();
					}
				}
				else {
					if(x.hand[3].Value() == x.hand[4].Value()) {
						result[0] = 2;
						result[1] = x.hand[4].Value();
						result[2] = x.hand[1].Value();
						result[3] = x.hand[2].Value();
					}
					else {
						result[0] = 1;
						result[1] = x.hand[1].Value();
						result[2] = x.hand[4].Value();
						result[3] = x.hand[3].Value();
						result[4] = x.hand[2].Value();
					}
				}
			}
		}
		else {
			if(x.hand[1].Value() == x.hand[2].Value()) {
				if(x.hand[1].Value() == x.hand[3].Value()) {
					if(x.hand[1].Value() == x.hand[4].Value()) {
						result[0] = 7;
						result[1] = x.hand[4].Value();
						result[2] = x.hand[0].Value();
					}
					else {
						result[0] = 3;
						result[1] = x.hand[3].Value();
						result[2] = x.hand[4].Value();
						result[3] = x.hand[0].Value();
					}
				}
				else {
					if(x.hand[3].Value() == x.hand[4].Value()) {
						result[0] = 2;
						result[1] = x.hand[4].Value();
						result[2] = x.hand[2].Value();
						result[3] = x.hand[0].Value();
					}
					else {
						result[0] = 1;
						result[1] = x.hand[2].Value();
						result[2] = x.hand[4].Value();
						result[3] = x.hand[3].Value();
						result[4] = x.hand[1].Value();
					}
				}
			}
			else {
				if(x.hand[2].Value() == x.hand[3].Value()) {
					if(x.hand[2].Value() == x.hand[4].Value()) {
						result[0] = 3;
						result[1] = x.hand[4].Value();
						result[2] = x.hand[1].Value();
						result[3] = x.hand[0].Value();
					}
					else {
						result[0] = 1;
						result[1] = x.hand[3].Value();
						result[2] = x.hand[4].Value();
						result[3] = x.hand[1].Value();
						result[4] = x.hand[0].Value();
					}
				}
				else {
					if(x.hand[3].Value() == x.hand[4].Value()) {
						result[0] = 1;
						result[1] = x.hand[4].Value();
						result[2] = x.hand[2].Value();
						result[3] = x.hand[1].Value();
						result[4] = x.hand[0].Value();
					}
					else {
						if(x.hand[0].colour == x.hand[1].colour & x.hand[0].colour == x.hand[2].colour & x.hand[0].colour == x.hand[3].colour & x.hand[0].colour == x.hand[4].colour) {
							if((x.hand[0].Value() + 4) == (x.hand[1].Value() + 3) & (x.hand[0].Value() + 4) == (x.hand[2].Value() + 2) & (x.hand[0].Value() + 4) == (x.hand[3].Value() + 1) & (x.hand[0].Value() + 4) == x.hand[4].Value()) {
								result[0] = 8;
								result[1] = x.hand[4].Value();
							}
							else {
								result[0] = 5;
								result[1] = x.hand[4].Value();
								result[2] = x.hand[3].Value();
								result[3] = x.hand[2].Value();
								result[4] = x.hand[1].Value();
								result[5] = x.hand[0].Value();
							}
						}
						else {
							if((x.hand[0].Value() + 4) == (x.hand[1].Value() + 3) & (x.hand[0].Value() + 4) == (x.hand[2].Value() + 2) & (x.hand[0].Value() + 4) == (x.hand[3].Value() + 1) & (x.hand[0].Value() + 4) == x.hand[4].Value()) {
								result[0] = 4;
								result[1] = x.hand[4].Value();
							}
							else {
								result[0] = 0;
								result[1] = x.hand[4].Value();
								result[2] = x.hand[3].Value();
								result[3] = x.hand[2].Value();
								result[4] = x.hand[1].Value();
								result[5] = x.hand[0].Value();
							}
						}
					}
				}
			}
		}
		return result;
	}
	
	
	String WinnerCheck(PlayerInterface p1,PlayerInterface p2,PlayerInterface p3,PlayerInterface p4) {
		
		
		String win="";
		
		
		long a = Long.parseLong(StrParse(p1));
		long b = Long.parseLong(StrParse(p2));
		long c = Long.parseLong(StrParse(p3));
		long d = Long.parseLong(StrParse(p4));
		long[][] longTab=new long[2][4];
		
		longTab[0][0]=a; 
		longTab[1][0]=1;
		
		longTab[0][1]=b; 
		longTab[1][1]=2;
		
		longTab[0][2]=c; 
		longTab[1][2]=3;
		
		longTab[0][3]=d; 
		longTab[1][3]=4;
		
		long temp=0;
		int n=4;

		do
		{
			for (int i=0;i<n-1;i++)
			{
				if(longTab[0][i]>longTab[0][i+1])
				{
					temp=longTab[0][i];
					longTab[0][i]=longTab[0][i+1];
					longTab[0][i+1]=temp;
					
					temp=longTab[1][i];
					longTab[1][i]=longTab[1][i+1];
					longTab[1][i+1]=temp;
				}
			}
			n=n-1;
		}
		while (n>1);
		
		int g=0;
		int[] temp1={0,0,0,0};
		for(int i=0;i<3;i++)
		{
			if (longTab[0][3]==longTab[0][i])
			{
				g++;
			}
		}
		for (int i=0;i<=g;i++)
		{
			temp1[i]=(int)longTab[1][3-i];
		}
		n=g+1;
		do
		{
			for (int i=0;i<n-1;i++)
			{
				if(temp1[i]>temp1[i+1])
				{
					temp=temp1[i];
					temp1[i]=temp1[i+1];
					temp1[i+1]=(int)temp;
				}
			}
			n=n-1;
		}
		while (n>1);
		
		for (int i=0;i<=g;i++)
		{
			if(temp1[i]==1)
				win=win+"1";
			if(temp1[i]==2)
				win=win+"2";
			if(temp1[i]==3)
				win=win+"3";
			if(temp1[i]==4)
				win=win+"4";
		}	
		return win;
	}
	
	String StrParse(PlayerInterface p1) {
		int tab3[] = CardCheck(p1);
		int g = 0;
		String figureTab[]={"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14"};
		String win = "";
		for(int x=0;x<15;x++) {
			if(tab3[0] == x) {
				win = win + figureTab[x];
				g++;
			}
		}
		for(int i=1;i<6;i++) {
			for(int j=2;j<15;j++) {
				if(tab3[i] == j) {
					if(j<10) {
						win = win + "0" + figureTab[j];
						g += 2;
					}
					else {
						win = win + figureTab[j];
						g += 2;
					}
				}
			}
		}
		for(int i=g;i<11;i++) {
			win=win+"0";
		}
		return win;
	}
}
